package system.config.rocketmq.producer;

import common.config.rocketmq.MqTaskEnum;
import common.config.rocketmq.RocketMqConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * RocketMQ生产者：账号删除
 *
 * @author 米泽鹏
 * @since 2022-07-24 上午 11:38
 */
@Component
@Slf4j
public class UserDrawDownMqProducer extends DefaultMQProducer implements InitializingBean, DisposableBean {

	@Value("${spring.application.name}")
	private String appName;

	@Override
	public void afterPropertiesSet() throws Exception {
		setNamesrvAddr(RocketMqConstants.NAMESERVER_ADDRESS);
		setProducerGroup(MqTaskEnum.USER_DRAW_DOWN.getProducerGroup());
		start();
		log.info("RocketMQ Producer启动成功，分组名称：" + MqTaskEnum.USER_DRAW_DOWN.getProducerGroup() + "，来自服务：" + appName);
	}

	@Override
	public void destroy() {
		shutdown();
		log.info("RocketMQ Producer关闭，分组名称：" + MqTaskEnum.USER_DRAW_DOWN.getProducerGroup() + "，来自服务：" + appName);
	}

}
